package club325.webchat.database.hibernate.implement;

import java.util.List;

import org.hibernate.Query;

import club325.webchat.database.hibernate.dao.GetPasswordDAO;
import club325.webchat.database.hibernate.dao.HibernateUtil;
import club325.webchat.database.hibernate.domain.GetPassword;

public class GetPasswordImplement implements GetPasswordDAO
{

	public void saveGetPassword(GetPassword getpwd)
	{
		HibernateUtil.add(getpwd);
	}

	public GetPassword findGetPasswordbyID(int id)
	{
		return (GetPassword) HibernateUtil.get(GetPassword.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<GetPassword> findGetPasswordbyMemberID(String owner)
	{
		String HQL = "FROM GetPassword AS getPassword WHERE getPassword.memberID = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0, owner);
		return q.list();
	}

	@SuppressWarnings("unchecked")
	public List<GetPassword> findGetPasswordbyQuestion(String Q)
	{
		String HQL = "FROM GetPassword AS getPassword WHERE getPassword.question = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0, Q);
		return q.list();
	}

	@SuppressWarnings("unchecked")
	public List<GetPassword> findGetPasswordbyAnswer(String A)
	{
		String HQL = "FROM GetPassword AS getPassword WHERE getPassword.answer = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0, A);
		return q.list();
	}

	public void remove(GetPassword getpwd)
	{
		HibernateUtil.delete(getpwd);
	}

	public void UpdateGetPassword(GetPassword getpwd)
	{
		HibernateUtil.Update(getpwd);
	}

}
